----------------------------------------------------------------
-- Global Variables
----------------------------------------------------------------

VictoryPointPairingData = {}

----------------------------------------------------------------
-- Local Variables
----------------------------------------------------------------

local PairingSelectionData = {}

----------------------------------------------------------------
-- Local Functions
----------------------------------------------------------------

--[[
    After the string table has been loaded, this is called
    to populate the pairing data with the correct values.
--]]
local function CreatePairingData ()

    if (GameData.Pairing.GREENSKIN_DWARVES == nil) then
        -- DEBUG (L"*** Game data has not been exported from WarInterface.");
        return;
    end
    
    if (StringTables.WorldControl.LABEL_RACIAL_PAIRING_DWARFS_GREENSKINS == nil) then
        -- DEBUG (L"*** The string table was not loaded!");
        return;
    end        

    PairingSelectionData = 
    {
        [GameData.Pairing.GREENSKIN_DWARVES] = 
        {
            stringTableID = StringTables.WorldControl.LABEL_RACIAL_PAIRING_DWARFS_GREENSKINS,

            tierNames =
            {
                { stringTableID = StringTables.WorldControl.LABEL_DG_TIER_1 },
                { stringTableID = StringTables.WorldControl.LABEL_DG_TIER_2 },
                { stringTableID = StringTables.WorldControl.LABEL_DG_TIER_3 },
                {
                    { zoneID = 110 },
                    { zoneID = 109 },
                    { zoneID = 105 },
                    { zoneID = 103 },
                    { zoneID = 104 },
                },
            },
        },

        [GameData.Pairing.EMPIRE_CHAOS] =
        {
            stringTableID = StringTables.WorldControl.LABEL_RACIAL_PAIRING_EMPIRE_CHAOS,
            tierNames =
            {
                { stringTableID = StringTables.WorldControl.LABEL_EC_TIER_1 },
                { stringTableID = StringTables.WorldControl.LABEL_EC_TIER_2 },
                { stringTableID = StringTables.WorldControl.LABEL_EC_TIER_3 },
                {
                    { zoneID = 110 },
                    { zoneID = 109 },
                    { zoneID = 105 },
                    { zoneID = 103 },
                    { zoneID = 104 },
                },
            },
        },

        [GameData.Pairing.ELVES_DARKELVES] = 
        {
            stringTableID = StringTables.WorldControl.LABEL_RACIAL_PAIRING_HIGHELVES_DARKELVES,
            tierNames =
            {
                { stringTableID = StringTables.WorldControl.LABEL_HD_TIER_1 },
                { stringTableID = StringTables.WorldControl.LABEL_HD_TIER_2 },
                { stringTableID = StringTables.WorldControl.LABEL_HD_TIER_3 },
                {
                    { zoneID = 110 },
                    { zoneID = 109 },
                    { zoneID = 105 },
                    { zoneID = 103 },
                    { zoneID = 104 },
                },
            },
        },
    }   

end


----------------------------------------------------------------
-- Global Functions
----------------------------------------------------------------

--[[
    Initialize the pairing data system
--]]
function VictoryPointPairingData.Initialize ()
    LoadStringTable("WorldControl", "data/strings/<LANG>", "worldcontrol.txt", "cache/<LANG>", "StringTables.WorldControl" )
    
    -- LoadStringTable returns nothing, so test one of the values that should be in the string table
    -- to make sure that it is non-nil.
    if (StringTables.WorldControl ~= nil) then
        CreatePairingData ();
    end
end

--[[
    Shutdown the pairing data system...
--]]
function VictoryPointPairingData.Shutdown ()
    PairingSelectionData = { };
    UnloadStringTable( "WorldControl" )
end

--[[
    Public accessor to the pairing data table for battlefront/tier/zone descriptions.
    
    Returns two strings, the [TIER X] text and the name of the zone
    Neither string will ever be nil, but they might be empty.
--]]

function VictoryPointPairingData.GetBattlefrontDesciption (pairing, tier, tier4Zone)    
    local description = L"";
    
    local tierTable = PairingSelectionData[pairing].tierNames;
    
    if (nil == tierTable) then 
        return description;
    end
    
    description = L"["..GetStringFromTable ("WorldControl", StringTables.WorldControl.LABEL_TIER_PREFIX)..L" "..tier..L"] ";
    
    local zoneName = L"";
    
    if (tier >= 1 and tier < 4) then
        zoneName = GetStringFromTable ("WorldControl", tierTable[tier].stringTableID);
    elseif (tier == 4 and (tier4Zone >= 1 and tier4Zone <= 5)) then
        zoneName = GetZoneName (tierTable[tier][tier4Zone].zoneID);
    end
    
    return description, zoneName;
end

--[[
    Public accessor to the pairing data table for racial pairings
--]]
function VictoryPointPairingData.GetRacialParingDescription (pairing)
    local description = L"";
    
    if (PairingSelectionData[pairing] ~= nil) then
        description = GetStringFromTable ("WorldControl", PairingSelectionData[pairing].stringTableID);
    end
    
    return (description);
end
